package com.xq.config;

import com.xq.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //需要拦截的路径，通常都是多个，所以使用数组形式
        String[] addPathPatterns = {
                "/**"
        };
        //不需要的拦截路径，同上
        String[] excludePathPatterns = {
                "/swagger-ui.html",
                "/register",
                "/login"
        };
        //可以将添加拦截的路径和不需要拦截的路径都写在一行上。如果有多个，就写多行
        registry.addInterceptor(loginInterceptor).addPathPatterns(addPathPatterns).excludePathPatterns(excludePathPatterns);
    }
}
